package leetcode.剑指offer.前40;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/7/21 23:09
 * @description：https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/
 */
public class 剑指_11_旋转数组的最小数字 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public int minArray(int[] nums) {
            int len = nums.length;
            int l = 0;
            int r = len - 1;
            int mid = 0;
            while (l < r && nums[l] == nums[r]) {
                l++;
            }
            while (l < r) {
                mid = l + r >> 1;
                if (nums[mid] <= nums[r]) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return nums[l];
        }
    }

}
